import {BrowserWindow, ipcMain} from 'electron'
import {createMainWindow} from './main'
import {createMainTray} from './tray'
import {createImWindow} from './im'
import {createNavicatWindow} from './navicat'

let loginWindow = null

const loginWindowURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080/#/login` : `file://${__dirname}/index.html#login`

export function createLoginWindow() {

    loginWindow = new BrowserWindow({
        frame: false,
        autoHideMenuBar: true,
        resizable: false,
        width: 700,
        height: 400,
        useContentSize: true
    })

    loginWindow.loadURL(loginWindowURL)
    loginWindow.webContents.openDevTools()
    loginWindow.on('closed', () => {
        loginWindow = null
    })
}


ipcMain.on('min-loginWindow', (event, arg) => {
    loginWindow.minimize()
})

ipcMain.on('close-loginWindow', (event, arg) => {
    loginWindow.close()
})

ipcMain.on('login-system', (event, arg) => {
    createNavicatWindow()
    // createMainWindow()
    // createMainTray()
    // createImWindow()
    loginWindow.close()
})